/**
 * 任务所需附体 编辑页
 *
 * 作者 ganjun
 * 日期 2024-11-18 10:54:56
 */
layui.use(['jquery','febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#taskAttach-edit'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    initFormValue();

    function initFormValue() {
        if (taskAttachData) {
            form.val("taskAttach-edit-form", {
                "id": taskAttachData.id,
                "id": taskAttachData.id,
                "taskCode": taskAttachData.taskCode,
                "attachCode": taskAttachData.attachCode,
            });
        }
    }

    form.on('submit(taskAttach-edit-form-submit)', function (data) {
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        febs.modal.confirm("保存提示！","是否保存？",function (index){
            if (data.id && data.id.length > 0) {
                febs.postArray(ctx + 'taskAttach/update', data, function () {
                    layer.closeAll();
                    febs.alert.success('修改成功');
                    febs.reloadPage();
                });
            } else {
                febs.postArray(ctx + 'taskAttach', data, function () {
                    layer.closeAll();
                    febs.alert.success('新增成功');
                    $('#febs-taskAttach').find('#query').trigger('click');
                });
            }
        })
    }
});